/*
 * @lc app=leetcode.cn id=572 lang=javascript
 *
 * [572] 另一个树的子树
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} s
 * @param {TreeNode} t
 * @return {boolean}
 */
var isSubtree = function(s, t) {
    if (!t) return true
    if (!s) return false
    if (s.val == t.val && check(s, t)) return true
    if (isSubtree(s.left, t)) return true
    if (isSubtree(s.right, t)) return true
    return false 
   
};

function check (p1, p2) {
   if (!p1 && !p2) return true
   if (!p1 || !p2) return false
   if (p1.val == p2.val) return check(p1.left, p2.left) && check(p1.right, p2.right)
   return false
}

// @lc code=end

